<?php

 if(isset($_POST['user']))
 {
  createUser($_POST['username'],$_POST['password'],$_POST['name']);
  $idstr = getUserIDFromUsername($_POST['username']);
  $id = (int)$idstr[0][0];
  createProfile($id, 'img/art/14.jpg', 'headline', 'bio');
 }
 if(isset($_POST['logged'])){
 	echo $_POST['logName'];
 	$result = checkUserLogin($_POST['logName'], $_POST['logPassword']);
 	echo $result;
 }
?>




<?php
function createUser($username, $password, $name)
{
	 // $conn = mysql_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 3306);
 	//  mysql_select_db('quirklco_new',$conn)


  $conn = mysqli_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 'quirklco_new', 3306);
  if(mysqli_connect_errno())
  {
   echo "Failed to connect: " . mysqli_connect_error();
  }

  $call = $conn->prepare('CALL quirklco_createUser(?,?,?)') or die ("nope");   
  $call->bind_param('sss',$username,$password,$name) or die ('didnt work 2nd step');
  $call->execute() or die ('didnt work 3rd step');

 // mysqli_query($conn, "CALL quirklco_createUser(".$username.",".$password.",".$name.")");
  mysqli_close($conn);
}

function getUserIDFromUsername($username)
{
 $conn = mysqli_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 'quirklco_new', 3306);
  if(mysqli_connect_errno())
  {
   echo "Failed to connect: " . mysqli_connect_error();
  }

  $call = $conn->prepare('CALL quirklco_getUserIDFromUsername(?)') or die ("nope");   
  $call->bind_param('s',$username) or die ('didnt bind param');
  $call->execute() or die ('did not execute correctly');
  $return_arr = array();
 do{
  if($result = $call->get_result()){
    printf("---\n");
   $return_arr = mysqli_fetch_all($result);
   mysqli_free_result($result);
   //echo "1";
  }
  else{
   if($call->errno){
    echo "Store Failed";
   }
  }
 } while($call->more_results() && $call->next_result());
 //$result = mysqli_query($conn, "CALL quirklco_featuredArt()");
 
 mysqli_close($conn);
 return $return_arr;
}

function checkUserLogin($username, $password)
{
 $conn = mysqli_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 'quirklco_new', 3306);
  if(mysqli_connect_errno())
  {
   echo "Failed to connect: " . mysqli_connect_error();
  }

  $call = $conn->prepare('CALL quirklco_loginUser(?,?)') or die ("nope");   
  $call->bind_param('ss',$username,$password) or die ('didnt bind param');
  $call->execute() or die ('did not execute correctly');
  $return_arr = array();
 do{
  if($result = $call->get_result()){
    printf("---\n");
   $return_arr = mysqli_fetch_all($result);
   mysqli_free_result($result);
   //echo "1";
  }
  else{
   if($call->errno){
    echo "Store Failed";
   }
  }
 } while($call->more_results() && $call->next_result());
 //$result = mysqli_query($conn, "CALL quirklco_featuredArt()");
 
 mysqli_close($conn);
 return $return_arr;
}



function getFeaturedArt()
{
	$conn = mysqli_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 'quirklco_new', 3306);
	if(mysqli_connect_errno())
	{
		echo "Failed to connect: " . mysqli_connect_error();
	}
	$call = $conn->prepare('CALL quirklco_featuredArt()') or die ('did not prepare');
	$call->execute() or die ('did not execute correctly');
	$return_arr = array();
	do{
		if($result = $call->get_result()){
			 printf("---\n");
			$return_arr = mysqli_fetch_all($result);
			mysqli_free_result($result);
			//echo "1";
		}
		else{
			if($call->errno){
				echo "Store Failed";
			}
		}
	} while($call->more_results() && $call->next_result());
	//$result = mysqli_query($conn, "CALL quirklco_featuredArt()");
	
	mysqli_close($conn);
	return $return_arr;
}

function getFeaturedMusic()
{
	$conn = mysqli_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 'quirklco_new', 3306);
	if(mysqli_connect_errno())
	{
		echo "Failed to connect: " . mysqli_connect_error();
	}
	$call = $conn->prepare('CALL quirklco_featuredMusic()') or die ('did not prepare');
	$call->execute() or die ('did not execute correctly');
	$return_arr = array();
	do{
		if($result = $call->get_result()){
			 printf("---\n");
			$return_arr = mysqli_fetch_all($result);
			mysqli_free_result($result);
			//echo "1";
		}
		else{
			if($call->errno){
				echo "Store Failed";
			}
		}
	} while($call->more_results() && $call->next_result());
	//$result = mysqli_query($conn, "CALL quirklco_featuredArt()");
	
	mysqli_close($conn);
	return $return_arr;
}

function getFeaturedPerformances()
{
	$conn = mysqli_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 'quirklco_new', 3306);
	if(mysqli_connect_errno())
	{
		echo "Failed to connect: " . mysqli_connect_error();
	}
	$call = $conn->prepare('CALL quirklco_featuredPerformances()') or die ('did not prepare');
	$call->execute() or die ('did not execute correctly');
	$return_arr = array();
	do{
		if($result = $call->get_result()){
			 printf("---\n");
			$return_arr = mysqli_fetch_all($result);
			mysqli_free_result($result);
			//echo "1";
		}
		else{
			if($call->errno){
				echo "Store Failed";
			}
		}
	} while($call->more_results() && $call->next_result());
	//$result = mysqli_query($conn, "CALL quirklco_featuredArt()");
	
	mysqli_close($conn);
	return $return_arr;
}

function getFeaturedFilm()
{
	$conn = mysqli_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 'quirklco_new', 3306);
	if(mysqli_connect_errno())
	{
		echo "Failed to connect: " . mysqli_connect_error();
	}
	$call = $conn->prepare('CALL quirklco_featuredFilm()') or die ('did not prepare');
	$call->execute() or die ('did not execute correctly');
	$return_arr = array();
	do{
		if($result = $call->get_result()){
			 printf("---\n");
			$return_arr = mysqli_fetch_all($result);
			mysqli_free_result($result);
			//echo "1";
		}
		else{
			if($call->errno){
				echo "Store Failed";
			}
		}
	} while($call->more_results() && $call->next_result());
	//$result = mysqli_query($conn, "CALL quirklco_featuredArt()");
	
	mysqli_close($conn);
	return $return_arr;
}

function getFeaturedSeries()
{
	$conn = mysqli_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 'quirklco_new', 3306);
	if(mysqli_connect_errno())
	{
		echo "Failed to connect: " . mysqli_connect_error();
	}
	$call = $conn->prepare('CALL quirklco_featuredSeries()') or die ('did not prepare');
	$call->execute() or die ('did not execute correctly');
	$return_arr = array();
	do{
		if($result = $call->get_result()){
			 printf("---\n");
			$return_arr = mysqli_fetch_all($result);
			mysqli_free_result($result);
			//echo "1";
		}
		else{
			if($call->errno){
				echo "Store Failed";
			}
		}
	} while($call->more_results() && $call->next_result());
	//$result = mysqli_query($conn, "CALL quirklco_featuredArt()");
	
	mysqli_close($conn);
	return $return_arr;
}

function getTopArt()
{
	$conn = mysqli_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 'quirklco_new', 3306);
	if(mysqli_connect_errno())
	{
		echo "Failed to connect: " . mysqli_connect_error();
	}
	$call = $conn->prepare('CALL quirklco_topArt()') or die ('did not prepare');
	$call->execute() or die ('did not execute correctly');
	$return_arr = array();
	do{
		if($result = $call->get_result()){
			 printf("---\n");
			$return_arr = mysqli_fetch_all($result);
			mysqli_free_result($result);
			//echo "1";
		}
		else{
			if($call->errno){
				echo "Store Failed";
			}
		}
	} while($call->more_results() && $call->next_result());
	//$result = mysqli_query($conn, "CALL quirklco_featuredArt()");
	
	mysqli_close($conn);
	return $return_arr;
}

function getTopMusic()
{
	$conn = mysqli_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 'quirklco_new', 3306);
	if(mysqli_connect_errno())
	{
		echo "Failed to connect: " . mysqli_connect_error();
	}
	$call = $conn->prepare('CALL quirklco_topMusic()') or die ('did not prepare');
	$call->execute() or die ('did not execute correctly');
	$return_arr = array();
	do{
		if($result = $call->get_result()){
			 printf("---\n");
			$return_arr = mysqli_fetch_all($result);
			mysqli_free_result($result);
			//echo "1";
		}
		else{
			if($call->errno){
				echo "Store Failed";
			}
		}
	} while($call->more_results() && $call->next_result());
	//$result = mysqli_query($conn, "CALL quirklco_featuredArt()");
	
	mysqli_close($conn);
	return $return_arr;
}

function getTopSeries()
{
	$conn = mysqli_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 'quirklco_new', 3306);
	if(mysqli_connect_errno())
	{
		echo "Failed to connect: " . mysqli_connect_error();
	}
	$call = $conn->prepare('CALL quirklco_topSeries()') or die ('did not prepare');
	$call->execute() or die ('did not execute correctly');
	$return_arr = array();
	do{
		if($result = $call->get_result()){
			 printf("---\n");
			$return_arr = mysqli_fetch_all($result);
			mysqli_free_result($result);
			//echo "1";
		}
		else{
			if($call->errno){
				echo "Store Failed";
			}
		}
	} while($call->more_results() && $call->next_result());
	//$result = mysqli_query($conn, "CALL quirklco_featuredArt()");
	
	mysqli_close($conn);
	return $return_arr;
}

function getTopFilm()
{
	$conn = mysqli_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 'quirklco_new', 3306);
	if(mysqli_connect_errno())
	{
		echo "Failed to connect: " . mysqli_connect_error();
	}
	$call = $conn->prepare('CALL quirklco_topFilm()') or die ('did not prepare');
	$call->execute() or die ('did not execute correctly');
	$return_arr = array();
	do{
		if($result = $call->get_result()){
			 printf("---\n");
			$return_arr = mysqli_fetch_all($result);
			mysqli_free_result($result);
			//echo "1";
		}
		else{
			if($call->errno){
				echo "Store Failed";
			}
		}
	} while($call->more_results() && $call->next_result());
	//$result = mysqli_query($conn, "CALL quirklco_featuredArt()");
	
	mysqli_close($conn);
	return $return_arr;
}

function getTopPerformances()
{
	$conn = mysqli_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 'quirklco_new', 3306);
	if(mysqli_connect_errno())
	{
		echo "Failed to connect: " . mysqli_connect_error();
	}
	$call = $conn->prepare('CALL quirklco_topPerformances()') or die ('did not prepare');
	$call->execute() or die ('did not execute correctly');
	$return_arr = array();
	do{
		if($result = $call->get_result()){
			 printf("---\n");
			$return_arr = mysqli_fetch_all($result);
			mysqli_free_result($result);
			//echo "1";
		}
		else{
			if($call->errno){
				echo "Store Failed";
			}
		}
	} while($call->more_results() && $call->next_result());
	//$result = mysqli_query($conn, "CALL quirklco_featuredArt()");
	
	mysqli_close($conn);
	return $return_arr;
}


function getArtById($id)
{
	 // $conn = mysql_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 3306);
 	//  mysql_select_db('quirklco_new',$conn)


  $conn = mysqli_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 'quirklco_new', 3306);
  if(mysqli_connect_errno())
  {
   echo "Failed to connect: " . mysqli_connect_error();
  }

  $call = $conn->prepare('CALL quirklco_getArtById(?)') or die ("nope");   
  $call->bind_param('i',$id) or die ('didnt work 2nd step');
  $call->execute() or die ('did not execute correctly');
	$return_arr = array();
	do{
		if($result = $call->get_result()){
			 printf("---\n");
			$return_arr = mysqli_fetch_all($result);
			mysqli_free_result($result);
			//echo "1";
		}
		else{
			if($call->errno){
				echo "Store Failed";
			}
		}
	} while($call->more_results() && $call->next_result());
	//$result = mysqli_query($conn, "CALL quirklco_featuredArt()");
	
	mysqli_close($conn);
	return $return_arr;
}

function getAllMusicFromUserID($id)
{
	 // $conn = mysql_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 3306);
 	//  mysql_select_db('quirklco_new',$conn)


  $conn = mysqli_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 'quirklco_new', 3306);
  if(mysqli_connect_errno())
  {
   echo "Failed to connect: " . mysqli_connect_error();
  }

  $call = $conn->prepare('CALL quirklco_getAllMusicFromUserID(?)') or die ("nope");   
  $call->bind_param('i',$id) or die ('didnt work 2nd step');
  $call->execute() or die ('did not execute correctly');
	$return_arr = array();
	do{
		if($result = $call->get_result()){
			 printf("---\n");
			$return_arr = mysqli_fetch_all($result);
			mysqli_free_result($result);
			//echo "1";
		}
		else{
			if($call->errno){
				echo "Store Failed";
			}
		}
	} while($call->more_results() && $call->next_result());
	//$result = mysqli_query($conn, "CALL quirklco_featuredArt()");
	
	mysqli_close($conn);
	return $return_arr;
}

function getAllPerformancesFromUserID($id)
{
	 // $conn = mysql_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 3306);
 	//  mysql_select_db('quirklco_new',$conn)


  $conn = mysqli_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 'quirklco_new', 3306);
  if(mysqli_connect_errno())
  {
   echo "Failed to connect: " . mysqli_connect_error();
  }

  $call = $conn->prepare('CALL quirklco_getAllPerformancesFromUserID(?)') or die ("nope");   
  $call->bind_param('i',$id) or die ('didnt work 2nd step');
  $call->execute() or die ('did not execute correctly');
	$return_arr = array();
	do{
		if($result = $call->get_result()){
			 printf("---\n");
			$return_arr = mysqli_fetch_all($result);
			mysqli_free_result($result);
			//echo "1";
		}
		else{
			if($call->errno){
				echo "Store Failed";
			}
		}
	} while($call->more_results() && $call->next_result());
	//$result = mysqli_query($conn, "CALL quirklco_featuredArt()");
	
	mysqli_close($conn);
	return $return_arr;
}

function getAllFilmFromUserID($id)
{
	 // $conn = mysql_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 3306);
 	//  mysql_select_db('quirklco_new',$conn)


  $conn = mysqli_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 'quirklco_new', 3306);
  if(mysqli_connect_errno())
  {
   echo "Failed to connect: " . mysqli_connect_error();
  }

  $call = $conn->prepare('CALL quirklco_getAllFilmFromUserID(?)') or die ("nope");   
  $call->bind_param('i',$id) or die ('didnt work 2nd step');
  $call->execute() or die ('did not execute correctly');
	$return_arr = array();
	do{
		if($result = $call->get_result()){
			 printf("---\n");
			$return_arr = mysqli_fetch_all($result);
			mysqli_free_result($result);
			//echo "1";
		}
		else{
			if($call->errno){
				echo "Store Failed";
			}
		}
	} while($call->more_results() && $call->next_result());
	//$result = mysqli_query($conn, "CALL quirklco_featuredArt()");
	
	mysqli_close($conn);
	return $return_arr;
}

function getAllSeriesFromUserID($id)
{
	 // $conn = mysql_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 3306);
 	//  mysql_select_db('quirklco_new',$conn)


  $conn = mysqli_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 'quirklco_new', 3306);
  if(mysqli_connect_errno())
  {
   echo "Failed to connect: " . mysqli_connect_error();
  }

  $call = $conn->prepare('CALL quirklco_getAllSeriesFromUserID(?)') or die ("nope");   
  $call->bind_param('i',$id) or die ('didnt work 2nd step');
  $call->execute() or die ('did not execute correctly');
	$return_arr = array();
	do{
		if($result = $call->get_result()){
			 printf("---\n");
			$return_arr = mysqli_fetch_all($result);
			mysqli_free_result($result);
			//echo "1";
		}
		else{
			if($call->errno){
				echo "Store Failed";
			}
		}
	} while($call->more_results() && $call->next_result());
	//$result = mysqli_query($conn, "CALL quirklco_featuredArt()");
	
	mysqli_close($conn);
	return $return_arr;
}

function getAllArtFromUserID($id)
{
	 // $conn = mysql_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 3306);
 	//  mysql_select_db('quirklco_new',$conn)


  $conn = mysqli_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 'quirklco_new', 3306);
  if(mysqli_connect_errno())
  {
   echo "Failed to connect: " . mysqli_connect_error();
  }

  $call = $conn->prepare('CALL quirklco_getAllArtFromUserID(?)') or die ("nope");   
  $call->bind_param('i',$id) or die ('didnt work 2nd step');
  $call->execute() or die ('did not execute correctly');
	$return_arr = array();
	do{
		if($result = $call->get_result()){
			 printf("---\n");
			$return_arr = mysqli_fetch_all($result);
			mysqli_free_result($result);
			//echo "1";
		}
		else{
			if($call->errno){
				echo "Store Failed";
			}
		}
	} while($call->more_results() && $call->next_result());
	//$result = mysqli_query($conn, "CALL quirklco_featuredArt()");
	
	mysqli_close($conn);
	return $return_arr;
}




function getMusicById($id)
{
	 // $conn = mysql_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 3306);
 	//  mysql_select_db('quirklco_new',$conn)


  $conn = mysqli_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 'quirklco_new', 3306);
  if(mysqli_connect_errno())
  {
   echo "Failed to connect: " . mysqli_connect_error();
  }

  $call = $conn->prepare('CALL quirklco_getMusicFromId(?)') or die ("nope");   
  $call->bind_param('i',$id) or die ('didnt work 2nd step');
  $call->execute() or die ('did not execute correctly');
	$return_arr = array();
	do{
		if($result = $call->get_result()){
			 printf("---\n");
			$return_arr = mysqli_fetch_all($result);
			mysqli_free_result($result);
			//echo "1";
		}
		else{
			if($call->errno){
				echo "Store Failed";
			}
		}
	} while($call->more_results() && $call->next_result());
	//$result = mysqli_query($conn, "CALL quirklco_featuredArt()");
	
	mysqli_close($conn);
	return $return_arr;
}

function getPerformanceById($id)
{
	 // $conn = mysql_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 3306);
 	//  mysql_select_db('quirklco_new',$conn)


  $conn = mysqli_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 'quirklco_new', 3306);
  if(mysqli_connect_errno())
  {
   echo "Failed to connect: " . mysqli_connect_error();
  }

  $call = $conn->prepare('CALL quirklco_getPerformancebyId(?)') or die ("nope");   
  $call->bind_param('i',$id) or die ('didnt work 2nd step');
  $call->execute() or die ('did not execute correctly');
	$return_arr = array();
	do{
		if($result = $call->get_result()){
			 printf("---\n");
			$return_arr = mysqli_fetch_all($result);
			mysqli_free_result($result);
			//echo "1";
		}
		else{
			if($call->errno){
				echo "Store Failed";
			}
		}
	} while($call->more_results() && $call->next_result());
	//$result = mysqli_query($conn, "CALL quirklco_featuredArt()");
	
	mysqli_close($conn);
	return $return_arr;
}

function getFilmById($id)
{
	 // $conn = mysql_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 3306);
 	//  mysql_select_db('quirklco_new',$conn)


  $conn = mysqli_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 'quirklco_new', 3306);
  if(mysqli_connect_errno())
  {
   echo "Failed to connect: " . mysqli_connect_error();
  }

  $call = $conn->prepare('CALL quirklco_getFilmFromId(?)') or die ("nope");   
  $call->bind_param('i',$id) or die ('didnt work 2nd step');
  $call->execute() or die ('did not execute correctly');
	$return_arr = array();
	do{
		if($result = $call->get_result()){
			 printf("---\n");
			$return_arr = mysqli_fetch_all($result);
			mysqli_free_result($result);
			//echo "1";
		}
		else{
			if($call->errno){
				echo "Store Failed";
			}
		}
	} while($call->more_results() && $call->next_result());
	//$result = mysqli_query($conn, "CALL quirklco_featuredArt()");
	
	mysqli_close($conn);
	return $return_arr;
}

function getSeriesById($id)
{
	 // $conn = mysql_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 3306);
 	//  mysql_select_db('quirklco_new',$conn)


  $conn = mysqli_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 'quirklco_new', 3306);
  if(mysqli_connect_errno())
  {
   echo "Failed to connect: " . mysqli_connect_error();
  }

  $call = $conn->prepare('CALL quirklco_getSeriesById(?)') or die ("nope");   
  $call->bind_param('i',$id) or die ('didnt work 2nd step');
  $call->execute() or die ('did not execute correctly');
	$return_arr = array();
	do{
		if($result = $call->get_result()){
			 printf("---\n");
			$return_arr = mysqli_fetch_all($result);
			mysqli_free_result($result);
			//echo "1";
		}
		else{
			if($call->errno){
				echo "Store Failed";
			}
		}
	} while($call->more_results() && $call->next_result());
	//$result = mysqli_query($conn, "CALL quirklco_featuredArt()");
	
	mysqli_close($conn);
	return $return_arr;
}

function createProfile($userid, $profPicture, $headline, $bio)
{
  $conn = mysqli_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 'quirklco_new', 3306);
  if(mysqli_connect_errno())
  {
   echo "Failed to connect: " . mysqli_connect_error();
  }

  $call = $conn->prepare('CALL quirklco_createProfile(?,?,?,?)') or die ("nope");   
  $call->bind_param('isss',$userid,$profPicture,$headline,$bio) or die ('didnt work 2nd step');
  $call->execute() or die ('didnt work 3rd step');

 // mysqli_query($conn, "CALL quirklco_createUser(".$username.",".$password.",".$name.")");
  mysqli_close($conn);
}

function updateProfileByUserID($userid, $profPicture, $headline, $bio)
{
  $conn = mysqli_connect('198.252.65.4', 'quirklco_jtang', 'qwerty1234', 'quirklco_new', 3306);
  if(mysqli_connect_errno())
  {
   echo "Failed to connect: " . mysqli_connect_error();
  }

  $call = $conn->prepare('CALL quirklco_updateProfileByUserID(?,?,?,?)') or die ("nope");   
  $call->bind_param('isss',$userid,$profPicture,$headline,$bio) or die ('didnt work 2nd step');
  $call->execute() or die ('didnt work 3rd step');

 // mysqli_query($conn, "CALL quirklco_createUser(".$username.",".$password.",".$name.")");
  mysqli_close($conn);
}
?>